package com.wanxi.demo;

import java.util.Arrays;

/**
 * 通过交换位置进行数组反序排列
 */
public class ReversalArrayOther {
    public static void main(String[] args) {
        int[] arr = {11, 3, 54, 6, 7, 6};
        arr = reversal(arr);
        System.out.println(Arrays.toString(arr));
    }

    /**
     * @param arr
     * @return
     */
    private static int[] reversal(int[] arr) {
        int end = arr.length - 1;//数组的索引，从后往前数
        for (int i = 0; i < arr.length / 2; i++) {
            int temp = arr[i];
            arr[i] = arr[end - i];
            arr[end - i] = temp;
        }
        return arr;
    }
}
